package com.ctgu.tengyun.service.filetemplate.impl;

import com.ctgu.tengyun.dao.mybatis.FileTemplateMapper;
import com.ctgu.tengyun.domain.FileTemplate;
import com.ctgu.tengyun.domain.FileTemplateExample;
import com.ctgu.tengyun.service.filetemplate.FileTemplateService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by liaoweizhi on 2019/8/10.
 */
@Service
public class FileTemplateServiceImpl implements FileTemplateService {

    @Resource
    private FileTemplateMapper mapper;

    @Override
    public int insertSelective(FileTemplate record) {
        return mapper.insertSelective(record);
    }

    @Override
    public List<FileTemplate> selectByType(Integer templateType) {
        FileTemplateExample example = new FileTemplateExample();
        FileTemplateExample.Criteria criteria = example.createCriteria();

        criteria.andTemplateTypeEqualTo(templateType);
        criteria.andIsValidEqualTo(1);

        return mapper.selectByExample(example);
    }

    @Override
    public Integer countFileTemplate(Integer templateType) {
        FileTemplateExample example = new FileTemplateExample();
        FileTemplateExample.Criteria criteria = example.createCriteria();

        criteria.andIsValidEqualTo(1);
        if(null != templateType){
            criteria.andTemplateTypeEqualTo(templateType);
        }

        return mapper.countByExample(example);
    }

    @Override
    public List<FileTemplate> selectFileTemplateList(Integer templateType, Integer pageNo, Integer pageSize) {
        FileTemplateExample example = new FileTemplateExample();
        FileTemplateExample.Criteria criteria = example.createCriteria();

        criteria.andIsValidEqualTo(1);
        if(null != templateType){
            criteria.andTemplateTypeEqualTo(templateType);
        }

        example.setStartIndex((pageNo - 1) * pageSize);
        example.setPageSize(pageSize);

        return mapper.selectByExample(example);
    }

    @Override
    public FileTemplate selectByPrimaryKey(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(FileTemplate record) {
        return mapper.updateByPrimaryKeySelective(record);
    }
}
